package cn.zyq.ykb.controller.mgt.course;

import cn.zyq.ykb.beans.course.Course;
import cn.zyq.ykb.service.course.CourseService;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.common.PageParam;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.system.ry.util.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 课程-轮播图Controller
 *
 * @author SystemAuth
 * @date 2023-06-01
 */

@RestController(value = "MgtCourseController")
@RequestMapping("/mgt/course")
@Api(tags = "商学院课程接口")
public class CourseController extends BaseController {

    @Autowired
    private CourseService courseService;

    /**
     * 查询课程-轮播图列表
     */
    @ApiOperation(value = "列表", response = Course.class)
    @PostMapping("/list")
    public Object list(@RequestBody PageParam pageParam) {
        return this.courseService.selectCourseList(pageParam);
    }

     /**
      * 导出课程-轮播图列表
      */
     @ApiOperation(value = "导出")
     @Log(title = "课程-轮播图" , businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, Course courseChart) {
         List<Course> list = courseService.selectCourseList(courseChart);
         ExcelUtil<Course> util = new ExcelUtil<Course>(Course. class);
         util.exportExcel(response, list, "课程-轮播图数据");
     }

    /**
     * 获取课程-轮播图详细信息
     */
    @ApiOperation(value = "详情", response = Course.class)
    @GetMapping(value = "/{courseChartID}")
    public Object getInfo(@PathVariable("courseChartID") Integer courseChartID) {
        return this.courseService.selectCourseByCourseID(courseChartID);
    }
    /**
     * 获取课程-轮播图详细信息
     */
    @ApiOperation(value = "详情", response = Course.class)
    @GetMapping(value = "/detail/{serviceID}")
    public Object getInfo(@PathVariable(value = "serviceID") String serviceID) {
        return this.courseService.selectCourseByServiceID(serviceID);
    }

    /**
     * 新增课程-轮播图
     */
    @ApiOperation(value = "新增")
    @Log(title = "课程-轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody Course courseChart) {
        return this.courseService.insertCourse(courseChart);
    }

    /**
     * 修改课程-轮播图
     */
    @ApiOperation(value = "编辑")
    @Log(title = "课程-轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public Object edit(@RequestBody Course courseChart) {
        return this.courseService.updateCourse(courseChart);
    }

    /**
     * 删除课程-轮播图
     */
    @ApiOperation(value = "删除")
    @Log(title = "课程-轮播图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{courseChartIDs}")
    public Object remove(@PathVariable Integer[] courseChartIDs) {
        return this.courseService.deleteCourseByCourseIDs(courseChartIDs);
    }
}
